<template>
  <div class="widget_settings_pro">
    <ele-form-section
        labelPosition="left"
        v-model="formData"
        :request-fn="handleSubmit"
        :sections="sections"
    >
      <template v-slot:form-btn="{ btns }">
        <div
            class="rest-btn"
            @click="reset"
        >
          <svg-icon icon-class="reset-settings"></svg-icon>
          重置配置
        </div>
      </template>
    </ele-form-section>
  </div>
</template>

<script>
import { debounce, deepClone } from '@/utils/utils';

export default {
    name: 'twoImagesForm',
    props: {
        value: {
            type: Object,
            default: () => ({})
        }
    },
    computed: {
        formData: {
            get () {
                return JSON.parse(this.value.styleJson);
            },
            set: debounce(function (newValue) {
                this.value.styleJson = JSON.stringify(newValue);
                this.$store.commit('SET_PROJECT_DATA', this.value);
            }, 600)
        }
    },
    data () {
        return {
            pageCount: 0,
            activeNames: [],
            uploadPath: process.env.VUE_APP_BASE_API + '/upload-file',
            sections: [
                {
                    // 分区标题
                    title: '图1',
                    // 分区表单项
                    // 和group不同，仅将vue-ele-form的formDesc放入section中
                    formDesc: {
                        'image_src_1': {
                            label: '图片',
                            type: 'ele-form-upload-plus-file',
                            attrs: {
                                title: '添加图片',
                                desc: '建议尺寸：宽度1000px,高度可自适应'
                            }
                        },
                        'url_1': {
                            type: 'ele-form-custom-select',
                            label: '链接'
                        }
                    }
                },
                {
                    title: '图2',
                    formDesc: {
                        'image_src_2': {
                            label: '图片',
                            type: 'ele-form-upload-plus-file',
                            attrs: {
                                title: '添加图片',
                                desc: '建议尺寸：宽度1000px,高度可自适应'
                            }
                        },
                        'url_2': {
                            type: 'ele-form-custom-select',
                            label: '链接'
                        }
                    }
                },
                {
                    title: '图3',
                    formDesc: {
                        'image_src_3': {
                            label: '图片',
                            type: 'ele-form-upload-plus-file',
                            attrs: {
                                title: '添加图片',
                                desc: '建议尺寸：宽度1000px,高度可自适应'
                            }
                        },
                        'url_3': {
                            type: 'ele-form-custom-select',
                            label: '链接'
                        }
                    }
                },
                {
                    title: '图4',
                    formDesc: {
                        'image_src_4': {
                            label: '图片',
                            type: 'ele-form-upload-plus-file',
                            attrs: {
                                title: '添加图片',
                                desc: '建议尺寸：宽度1000px,高度可自适应'
                            }
                        },
                        'url_4': {
                            type: 'ele-form-custom-select',
                            label: '链接'
                        }
                    }
                }
            ]
        };
    },
    methods: {
        handleResponse (response, file, fileList) {
            return response;
        },
        handleSubmit (data) {
            console.log(data);
            return Promise.resolve();
        },
        reset () {
            this.pageCount = 0;
            this.$emit('resetData', this.value);
        }
    }
};
</script>

<style scoped lang="scss">
.form-item-inline {
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-left: 10px;
  padding-right: 10px;
  color: #606266;
  height: 32px;
  margin-bottom: 10px;
}
.editForm {
  margin-bottom: 10px;
  .form-item {
    margin-top: 10px;
    label {
      display: block;
      height: 32px;
      line-height: 32px;
    }
  }
  ::v-deep .el-collapse-item__content {
    border: 1px solid #d8deec;
    border-top: 0;
    padding-left: 10px;
  }
}
.addBtn {
  width: 100%;
}
</style>
